<?php

  abstract class DateUtils {

    /** @var integer The expression of the UNIX start time in milliseconds. */
    public static $UNIX_START_TIME = -3600;

    /** @var integer The expression of a day in milliseconds . */
    public static $MILLIS_PER_DAY = 8640000;

    /** @var integer The expression of an hour in milliseconds . */
    public static $MILLIS_PER_HOUR = 3600000;

    /** @var integer The expression of a minute in milliseconds . */
    public static $MILLIS_PER_MINUTE = 60000;

    /** @var integer The expression of a second in milliseconds . */
    public static $MILLIS_PER_SECOND = 1000;

    /** @var string The european date format. */
    public static $EUROPEAN_DATE_FORMAT = "d/m/Y";

    /**
     * Parse about any English textual datetime description into a Unix timestamp.
     *
     * @param String $date A date or time string.
     * @return mixed Returns a timestamp on success, false otherwise.
     * Previous to PHP 5.1.0, this function would return -1 on failure.
     * @link http://be.php.net/manual/en/function.strtotime.php
     * @link http://be.php.net/manual/en/datetime.formats.php
     */
    public static function FromDateToTimeStamp(String $date) {
      return strtotime($date->toString());
    }

    /**
     * Reverts an european date (dd/mm/yyyy) to an american date (yyyy/mm/dd).
     *
     * @param String $date A date string in european format.
     * @return String A date string in american format.
     * @link http://be.php.net/manual/en/function.explode.php
     * @link http://be.php.net/manual/en/function.count.php
     */
    public static function FromEuropeanToAmerican(String $date) {
      try {
        $ar = explode("/", $date->toString());

        if (count($ar) == 3) {
          return new String($ar[2] . "/" . $ar[1] . "/" . $ar[0]);
        } else {
          return new Boolean(false);
        }
      } catch (Exception $ex) {
        return new Boolean(false);
      }
    }

    /**
     * Format a local time or date.
     *
     * @param mixed $timestamp An integer Unix timestamp.
     * @param String $format The format of the outputted date string.
     * @return String Returns a formatted date string.
     * If a non-numeric value is used for timestamp, false is returned and an E_WARNING level error is emitted.
     */
    public static function Format($timestamp, String $format = null) {
      if ($format == null) {
        return new String(date("d/m/Y", $timestamp));
      } else {
        return new String(date($format->toString(), $timestamp));
      }
    }

    /**
     * Defines if it's a leap year.
     *
     * @param mixed $timestamp An integer Unix timestamp.
     * @return Boolean Returns true if it's a leap year, false otherwise.
     */
    public static function isLeap($timestamp) {
      var_dump(date("L", $timestamp));
      return Boolean::parseBoolean(date("L", $timestamp));
    }

  }

?>
